package cn.hesion.inputformat;
/**
 * ClassName: CustomFileInputFormat <br/>
 * Description: <br/>
 * date: 2021/2/3 17:05<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.ByteWritable;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import java.io.IOException;

/**
 * @program: ClientDemo
 * @description: 自定义InputFormar类
 * @author: hesion
 * @create: 2021-02-03 17:05
 **/
public class CustomFileInputFormat extends FileInputFormat<Text, BytesWritable> {


    @Override
    protected boolean isSplitable(JobContext context, Path filename) {
        return false;
    }


    @Override
    public RecordReader<Text, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        CustomRecordReader recordReader = new CustomRecordReader();
        recordReader.initialize(split,context);

        return recordReader;
    }
}
